(function () {

	//获取项目合同细目其他数据 服务器分页
    var contractOtherData = {};
    contractOtherData.contractId=jQuery('#contractId').val();
    //contractOtherData.contractViewType=jQuery('#contractType').val();
    var serverOtherTable;
    //获取合同泵数据
    var contractPumpData = {};
    contractPumpData.contractId=jQuery('#contractId').val();
    //contractPumpData.contractViewType=jQuery('#contractType').val();
    var serverPumpTable;
    //获取备件合同数据
    var beijianTableData = {};
    beijianTableData.contractViewId=jQuery('#contractId').val();
    beijianTableData.contractViewType="备件合同";
    var serverbeijianTable;
    //获取维修合同数据
    var serverweixiuTableData = {};
    serverweixiuTableData.contractViewId=jQuery('#contractId').val();
    serverweixiuTableData.contractViewType="维修合同";
    var serverweixiuTable;
    //获取备泵合同数据
    var serverbeibengTableData = {};
    serverbeibengTableData.contractViewId=jQuery('#contractId').val();
    serverbeibengTableData.contractViewType="备泵合同";
    var serverbeibengTable;
    //获取售后维护数据
    var shouhouTableData = {};
    shouhouTableData.contractViewId=jQuery('#contractId').val();
    shouhouTableData.contractViewType=jQuery('#contractType').val();
    var servershouhouTable;
    var urlPump = window.rootPath;
    var urlOther = window.rootPath;
    var urltype = window.rootPath;
    jQuery(document).ready(function () {
    	if($('#contractType').val()=="项目合同"){
    		/*urlOther += '/ui/contract/getReplacement';
    		urlPump += '/ui/contract/getDevice';
    		urltype += '/ui/contractviewindex/getbeijianView';//关联合同*/
    		jQuery('#beijan').hide();
    		jQuery('#weixiu1').hide();
    		jQuery('#weixiu2').hide();
    		jQuery('#projectCode21').hide();
    		jQuery('#projectCode22').hide();
    		var scheduleDate = jQuery('#scheduleDate1').val();
    		jQuery('#scheduleDate').val(moment(scheduleDate).format('YYYY-MM-DD'))
    		serverOtherTable.draw();
    		serverPumpTable.draw();
    		serverbeijianTable.draw();
    		serverweixiuTable.draw();
    		servershouhouTable.draw();
    	}
    	else if($('#contractType').val()=="备件合同"){
    		/*urlOther += '/ui/contract/getReplacement';*/
    		jQuery('#xiangmu').hide();
    		jQuery('#weixiu1').hide();
    		jQuery('#weixiu2').hide();
    		jQuery('#projectCode21').hide();
    		jQuery('#projectCode22').hide();
    		serverOtherTable.draw();
    		jQuery('#1').hide();
    		jQuery('#2').hide();
    		jQuery('#4').hide();
    		jQuery('#5').hide();
    		
    	}
    	else if($('#contractType').val()=="备泵合同"){
    		/*urlPump += '/ui/contract/getDevice';*/
    		jQuery('#xiangmu').hide();
    		jQuery('#weixiu1').hide();
    		jQuery('#weixiu2').hide();
    		jQuery('#projectCode21').hide();
    		jQuery('#projectCode22').hide();
    		serverPumpTable.draw();
    		jQuery('#1').hide();
    		jQuery('#2').hide();
    		jQuery('#6').hide();
    		jQuery('#resultOtherTable').hide();
    		
    	}
    	else if($('#contractType').val()=="维修合同"){
    		/*urlOther += '/ui/contract/getReplacement';
    		urlPump += '/ui/contract/getDevice';*/
    		jQuery('#beijan').hide();
    		jQuery('#xiangmu').hide();
    		var repairDate = jQuery('#repairDate1').val();
    		jQuery('#repairDate').val(moment(repairDate).format('YYYY-MM-DD'))
    		serverOtherTable.draw();
    		serverPumpTable.draw();
    		jQuery('#1').hide();
    		jQuery('#2').hide();
    	}
    	var supplierCode = jQuery('#supplierCode').val();
    	var url=window.rootPath+"/ui/contractviewindex/getSpeed?supplierCode="+supplierCode;
    	$.ajax({
            type: "GET", 
            dataType: 'json',
            async: false, 
            url: encodeURI(url),
            success: function(data) {
            	$("#sheji").progressbar({
            		value: data.sheji
            	});
            	$("#sheji_label").text($("#sheji").progressbar( "value" ) + "%" );

            	$("#peizhi").progressbar({
            		value: data.peizhi
            	});
            	$("#peizhi_label").text($("#peizhi").progressbar( "value" ) + "%" );
            	
            	$("#jiagong").progressbar({
            		value: data.jiagong
            	});
            	$("#jiagong_label").text($("#jiagong").progressbar( "value" ) + "%" );
            	
            	$("#caigou").progressbar({
            		value: data.caigou
            	});
            	$("#caigou_label").text($("#caigou").progressbar( "value" ) + "%" );
            	
            	$("#waixie").progressbar({
            		value: data.waixie
            	});
            	$("#waixie_label").text($("#waixie").progressbar( "value" ) + "%" );
            	
            	$("#zhuangpei").progressbar({
            		value: data.zhuangpei
            	});
            	$("#zhuangpei_label").text($("#zhuangpei").progressbar( "value" ) + "%" );
            	
            	$("#shishui").progressbar({
            		value: data.shishui
            	});
            	$("#shishui_label").text($("#shishui").progressbar( "value" ) + "%" );
            	
            	$("#youqi").progressbar({
            		value: data.youqi
            	});
            	$("#youqi_label").text($("#youqi").progressbar( "value" ) + "%" );
            	
            	$("#fengxiang").progressbar({
            		value: data.fengxiang
            	});
            	$("#fengxiang_label").text($("#fengxiang").progressbar( "value" ) + "%" );
            }
        });
    	
    	/*var progressbar = $("#sheji"),
        progressLabel = $(".progress-label");
    	progressbar.progressbar({
    	      value: 35,
    	      change: function() {
    	        progressLabel.text( progressbar.progressbar( "value" ) + "%" );
    	      },
    	      complete: function() {
    	        progressLabel.text( "完成！" );
    	      }
    	    });*/
    	 
    });
    
    
    serverOtherTable = jQuery('#resultOtherTable').DataTable({
		"serverSide": true,
        "ordering": false,
        "ajax": {
            "dataType": "json",
            "type": "get",
            "cache": false,
            "url":window.rootPath+ '/ui/contract/getReplacement',
            "data": function (d) {
                return $.extend({}, d, contractOtherData);
            }
        },
        columns: [
            {
            	data: null
            },
            {
                data: 'deviceName'
            },
            {
                data: 'type'
            },
            {
            	data: 'material'
            },
            {
            	data: 'unit'
            },
            {
                data: 'amount'
            },
            {
                data: 'price'
            }
            ],
        "drawCallback": function (oSettings) {
            var k = 0;
            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

            for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                k++;
            }
        }
    });
	
	serverPumpTable = jQuery('#resultPumpTable').DataTable({
        "serverSide": true,
        "ordering": false,
        "ajax": {
            "dataType": "json",
            "type": "get",
            "cache": false,
            "url":window.rootPath+ '/ui/contract/getDevice',
            "data": function (d) {
                return $.extend({}, d, contractPumpData);
            }
        },
        columns: [
            {
            	data: null
            },
            {
                data: 'productName'
            },
            {
                data: 'productType'
            },
            {
                data: 'subDivideType'
            },
            {
            	data: 'productModel'
            },
            {
                data: 'number'
            },
            {
                data: 'unitPrice'
            },
            {
                data: 'power'
            },
            {
                data: 'flowMaterial'
            },
            {
                data: 'transMedia'
            },
            {
                data: 'viscosity'
            },
            {
                data: 'flux'
            },
            {
                data: 'pumpLift'
            },
            {
                data: 'temperature'
            },
            {
                data: 'proportion'
            },
            {
                data: 'inPressure'
            },
            {
                data: 'effectiveNPSHA'
            },
            {
                data: 'mustMPSHA'
            },
            {
                data: 'nBillType',
                	render: function (data, type, full, meta) {
                 	var dOut;
                 	 if(data==0){
                 		dOut = '<td class="center" >自制件</td>';
                 	}
                 	else if(data==1){
                 		dOut = '<td class="center" >外购件</td>';
                 	}
 	            	return dOut;
                 }
            },
            {
                data: 'cMotor'
            },
            {
                data: 'cAttachment'
            },
            {
                data: 'cSysPump'
            },
            {
                data: 'cPumpType'
            },
            {
                data: 'nPumpNum'
            },
            {
                data: 'nPumpTotalPrice'
            },
            {
                data: 'dDeliveryDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY-MM-DD');
                    else
                        return '';
                }
            },
            {
                data: 'nIsSpecial',
            	render: function (data, type, full, meta) {
                 	var aOut;
                 	 if(data==0){
                 		aOut = '<td class="center" >是</td>';
                 	}
                 	else if(data==1){
                 		aOut = '<td class="center" >否</td>';
                 	}
 	            	return aOut;
                 }
            },
            {
                data: 'cStructure'
            },
            {
                data: 'cOutletPressure'
            },
            {
                data: 'cBitNumber'
            },
            {
                data: 'cUnit'
            },
            {
                data: 'cMemo'
            }],
        "drawCallback": function (oSettings) {
            var k = 0;
            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

            for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                k++;
            }
        }
    });
	
	serverbeijianTable = jQuery('#beijianTable').DataTable({
		"serverSide": true,
        "ordering": false,
        "ajax": {
            "dataType": "json",
            "type": "get",
            "cache": false,
            "url":window.rootPath+ '/ui/contractviewindex/getbeijianView',
            "data": function (d) {
                return $.extend({}, d, beijianTableData);
            }
        },
        columns: [
            {
            	data: null
            },
            {
                data: 'supplierCode'
            },
            {
            	data: 'contractType'
            },
            {
            	data: 'state'
            },
            {
                data: 'belongArea'
            },
            {
                data: 'totalSum'
            },
            {
                data: 'signedDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'scheduleDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'giveOutDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'deliveryDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'debugDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'acceptanceDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'stop'
            },
            {
                data: 'freightCharge'
            },
            {
                data: 'projectName'
            },
            {
                data: 'orderUnit'
            },
            {
                data: 'orderAddress'
            }
            ],
        "drawCallback": function (oSettings) {
            var k = 0;
            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

            for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                k++;
            }
        }
    });
	
	serverweixiuTable = jQuery('#weixiuTable').DataTable({
		"serverSide": true,
        "ordering": false,
        "ajax": {
            "dataType": "json",
            "type": "get",
            "cache": false,
            "url":window.rootPath+ '/ui/contractviewindex/getbeijianView',
            "data": function (d) {
                return $.extend({}, d, serverweixiuTableData);
            }
        },
        columns: [
            {
            	data: null
            },
            {
                data: 'supplierCode'
            },
            {
            	data: 'contractType'
            },
            {
            	data: 'state'
            },
            {
                data: 'belongArea'
            },
            {
                data: 'totalSum'
            },
            {
                data: 'signedDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'scheduleDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'giveOutDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'deliveryDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'debugDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'acceptanceDate',
                render: function (data, type, full, meta) {
                    if (data)
                        return moment(data).format('YYYY/MM/DD');
                    else
                        return '';
                }
            },
            {
                data: 'stop'
            },
            {
                data: 'freightCharge'
            },
            {
                data: 'projectName'
            },
            {
                data: 'orderUnit'
            },
            {
                data: 'orderAddress'
            }
            ],
        "drawCallback": function (oSettings) {
            var k = 0;
            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

            for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                k++;
            }
        }
    });
	
	serverbeibengTable = jQuery('#beibengTable').DataTable({
		"serverSide": true,
		"ordering": false,
		"ajax": {
			"dataType": "json",
			"type": "get",
			"cache": false,
			"url":window.rootPath+ '/ui/contractviewindex/getbeijianView',
			"data": function (d) {
				return $.extend({}, d, serverbeibengTableData);
			}
		},
		columns: [
		          {
		        	  data: null
		          },
		          {
		                data: 'supplierCode'
		            },
		            {
		            	data: 'contractType'
		            },
		            {
		            	data: 'state'
		            },
		            {
		                data: 'belongArea'
		            },
		            {
		                data: 'totalSum'
		            },
		            {
		                data: 'signedDate',
		                render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            },
		            {
		                data: 'scheduleDate',
		                render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            },
		            {
		                data: 'giveOutDate',
		                render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            },
		            {
		                data: 'deliveryDate',
		                render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            },
		            {
		                data: 'debugDate',
		                render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            },
		            {
		                data: 'acceptanceDate',
		                render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            },
		            {
		                data: 'stop'
		            },
		            {
		                data: 'freightCharge'
		            },
		            {
		                data: 'projectName'
		            },
		            {
		                data: 'orderUnit'
		            },
		            {
		                data: 'orderAddress'
		            }
		            ],
		          "drawCallback": function (oSettings) {
		        	  var k = 0;
		        	  var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
		        	  
		        	  for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
		        		  $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
		        		  k++;
		        	  }
		          }
	});
	
	servershouhouTable = jQuery('#shouhouTable').DataTable({
		"serverSide": true,
		"ordering": false,
		"ajax": {
			"dataType": "json",
			"type": "get",
			"cache": false,
			"url":window.rootPath+ '/ui/contractviewindex/getshouhouView',
			"data": function (d) {
				return $.extend({}, d, shouhouTableData);
			}
		},
		columns: [
		          {
		        	  data: null
		          },
		          {
		        	  data: 'deviceName'
		          },
		          {
		        	  data: 'questionDetail'
		          },
		          {
		        	  data: 'afterSaleType'
		          },
		          {
		        	  data: 'serviceTime',
		        	  render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		          },
		          {
		        	  data: 'sendDate',//完成时间
		        	  render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		          },
		          {
		        	  data: 'assess'
		          }
		          ],
		          "drawCallback": function (oSettings) {
		        	  var k = 0;
		        	  var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
		        	  
		        	  for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
		        		  $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
		        		  k++;
		        	  }
		          }
	});
    
    
    
})();